#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QRegularExpression>
#include <QDateTime>
#include <QMessageBox>
#include <QJsonDocument>
#include <QJsonObject>
#include <QValueAxis>
#include <csignal>  // 添加这个头文件
#include <QNetworkInterface>  // 网络接口相关
#include <QHostAddress>       // IP地址处理
#include <QDebug>

void MainWindow::initializeFromConfig()
{
    // Network
    cameraIp = ConfigManager::instance().cameraIP();
    cameraPort = ConfigManager::instance().cameraPort();
    mcuIp = ConfigManager::instance().mcuIP();
    mcuPort = ConfigManager::instance().mcuPort();
    serverPort = ConfigManager::instance().icstcpPort();

    // 初始化从板卡IP
    for (int i = 0; i < 4; ++i) {
        statusLeds.slave[i].ip = ConfigManager::instance().slaveIp(i);
    }

    // Paths
    binPath = ConfigManager::instance().binPath();
    fitsSavePath = ConfigManager::instance().fitsPath();
    m_logDirectory = ConfigManager::instance().logPath();
    mountPath = ConfigManager::instance().mountPath();

    // Temperature
    ui->spinTemperature_2->setValue(ConfigManager::instance().ccdTargetTemp());


    // Update UI
    ui->lineEditCameraIp->setText(cameraIp);
    ui->spinBoxCameraPort->setValue(cameraPort);
    ui->lineEditMcuIp->setText(mcuIp);
    ui->spinBoxMcuPort->setValue(mcuPort);
    ui->lineEditBinPath->setText(binPath);
    ui->lineEditBinPath_2->setText(m_logDirectory);
    ui->lineEditFitsPath->setText(fitsSavePath);

}
